const commoneUrl = "https://mboshop.mbo-world.com:52012"; //公共路径

//post请求封装
function postRequest(url, data) {
	uni.showLoading({
		title: '加载中...'
	});
	var promise = new Promise((resolve, reject) => {
		var postData = data;
		uni.request({
			url: commoneUrl + url,
			// url:'http://172.16.23.190:8080'+url,
			data: postData,
			method: 'POST',
			header: {
				'content-type': 'application/json;charset=UTF-8',
				'Authorization': uni.getStorageSync('token')
			},
			// header:{'content-type':'application/json;charset=UTF-8','Authorization':'eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6ImQwOGEyNWRiLWViYjgtNDE5Zi1hYzFmLWIzNTQwYTUyOTYwYyJ9.ySPHTu1dTxgKRWAAW0Cbvyn-I8iGThhwx-r3ibZ9Pv4ry72pnWeJKEnXY-b0J2FbJ_Lmc5UfSkihCh55NNN4Vw'},
			success: function(res) {
				resolve(res.data);
				uni.hideLoading();
			},
			error: function(e) {
				reject('网络出错');

				uni.hideLoading();
				uni.showToast({
					title:'网络出错',
					icon:'error'
				})
			}
		})
	});
	return promise;
}

//get请求封装
function getRequest(url, data) {
	var promise = new Promise((resolve, reject) => {
		var postData = data;
		uni.request({
			url: commoneUrl + url,
			// url:'http://172.16.23.28:8080'+url,
			data: postData,
			method: "GET",
			dataType: 'json',
			header: {
				'content-type': 'application/json',
				'Authorization': uni.getStorageSync('token')
			},
			// header:{'content-type':'application/json;charset=UTF-8','Authorization':'eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjRmOWE2YzVlLWMwOTUtNGIxNy04ZTQ3LWMyNDA3ZWM1NDRlOSJ9.4x4zLAsQ1XWKWniUCMrcyU3Dp9rznp3hOm7D0MfbgcNvR-fYk-nUo43E-1OE2uJpZqKiAvuGYLKE2_dIDi9Q5g'},
			success: function(res) {
				resolve(res.data);
			},
			error: function(e) {
				reject('网络出错');
			}
		});
	});
	return promise;
}

module.exports = {
	post: postRequest,
	get: getRequest,

	commoneUrl,

};
